package com.ruoyi.yuyuan.Config;

import com.ruoyi.yuyuan.Service.IUserService;
import com.ruoyi.yuyuan.Utils.AuthorityInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author: kestrel
 * @Version:1.0
 * @since: 2023/2/22
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private IUserService userService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AuthorityInterceptor(userService,stringRedisTemplate))
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/user/login/wechat",
                        "/error"
                ).order(0);
    }
}
